package com.caregiver.watch.business.user.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * 血压状态枚举
 */
@Getter
public enum BloodPressureStatusEnum {
    
    NORMAL(0, "正常") {
        @Override
        public boolean match(int systolic, int diastolic) {
            return systolic < 120 && diastolic < 80;
        }
    },
    HIGH(1, "高压") {
        @Override
        public boolean match(int systolic, int diastolic) {
            return systolic >= 140 || diastolic >= 90;
        }
    },
    LOW(2, "低压") {
        @Override
        public boolean match(int systolic, int diastolic) {
            return systolic < 90 && diastolic < 60;
        }
    };

    // 舒张压
    private final int code;
    private final String description;

    BloodPressureStatusEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据编码获取血压状态枚举
     *
     * @param systolic 收缩压
     * @param diastolic 舒张压
     * @return 对应的血压状态枚举
     */
    public static BloodPressureStatusEnum parse(Integer systolic, Integer diastolic) {
        if (Objects.isNull(systolic) || Objects.isNull(diastolic)) {
            return NORMAL;
        }
        for (BloodPressureStatusEnum status : BloodPressureStatusEnum.values()) {
            if (status.match(systolic, diastolic)) {
                return status;
            }
        }
        return NORMAL;
    }

    public abstract boolean match(int systolic, int diastolic);
}
